package cn.madis.ymcc.utils;

import cn.madis.ymcc.dto.LoginJwtDto;
import cn.madis.ymcc.util.AssertUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class LoginSecurityContext {

    public static LoginJwtDto getLoginJwtDtoContext(){
        SecurityContext context = SecurityContextHolder.getContext();
        AssertUtil.isTrue(context.getAuthentication().isAuthenticated(),"没有登录");
        Object principal = context.getAuthentication().getPrincipal();
        return JSONObject.parseObject(principal.toString(),LoginJwtDto.class);
    }
}
